﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HeBianGu.General.WpfControlLib;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ZeroBug.PersonalityEvaluation
{
    public partial class MainWindowViewModel : ObservableObject
    {
        [ObservableProperty]
        UserControl? userView;

        private bool _isAdminLogin;
        public bool IsAdminLogin
        {
            get { return _isAdminLogin; }
            set 
            { 
                _isAdminLogin = value;
                if (_isAdminLogin)
                {
                    var vm = App.Current.Services.GetService<DataStatisticsViewModel>();
                    vm.LoadPerson();
                    vm.AdminName = App.Current.Services.GetService<LoginViewModel>().Name;
                    UserView = App.Current.Services.GetService<DataStatisticsView>();
                }
                else
                    UserView = App.Current.Services.GetService<EvaluationView>();
            }
        }


        [RelayCommand]
        void MinimizeWindow() => SystemCommands.MinimizeWindow(App.Current.Services.GetService(typeof(MainWindow)) as MainWindow);
        [RelayCommand]
        void MaximizeWindow()
        {
            MainWindow? window = App.Current.Services.GetService<MainWindow>();
            if (window != null)
            {
                if (window.WindowState == WindowState.Normal)
                    SystemCommands.MaximizeWindow(window);
                else
                    SystemCommands.RestoreWindow(window);
            }
        }
        [RelayCommand]
        void CloseWindow()
        {
            MainWindow? window = App.Current.Services.GetService<MainWindow>();
            if (window != null)
                SystemCommands.CloseWindow(window);
        }
        public MainWindowViewModel()
        {

        }
    }
}
